package com.fhao.spring.selfblog.service;


import com.fhao.spring.selfblog.mapper.UserInfoMapper;
import com.fhao.spring.selfblog.model.BlogInfo;
import com.fhao.spring.selfblog.model.Result;
import com.fhao.spring.selfblog.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private BlogService blogService;

    public UserInfo selectById(Integer id) {
        return userInfoMapper.selectById(id);
    }

    public UserInfo selectByName(String userName) {
        return userInfoMapper.selectByName(userName);
    }

    public UserInfo getAuthorInfo(Integer blogId) {
        //2.根据博客id获取到用户id
        BlogInfo blogInfo = blogService.selectByid(blogId);
        if(blogInfo == null || blogInfo.getUserId() <= 0) {
            return null;
        }
        Integer userId = blogInfo.getUserId();
        //3. 根据用户id获取博客作者信息
        UserInfo userInfo = userInfoMapper.selectById(userId);
        return userInfo;
    }
}
